﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Vaffanculo.Business.Managers;
using Vaffanculo.Data.Interfaces;
using Vaffanculo.Data.Implements;
using Vaffanculo.Model.Entities;

namespace Vaffanculo.Business.Tests
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestClass]
    public class ProjectManagerTest : BaseTestClass
    {
        public ProjectManagerTest()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestMethod]
        public void GetAllProjects()
        {
            //
            // TODO: Add test logic here
            //
        }

        [TestMethod]
        public void AddProjectManagerTest()
        {
            int beforeInsert = 0;
            int afterInsert = 0;
            ProjectManager projectManager = null;

            /*
            // Object context definition to specific model/database
            DbContextVaffanculoTest contextVaffanculo = new DbContextVaffanculoTest();

            IDbContext context = new DbContextAdap(contextVaffanculo);
            IUnitOfWork uow = new UnitOfWork(context);
            projectManager = new ProjectManager(uow);
            beforeInsert = projectManager.GetCount();
            // Create Object type Project
            Project project = new Project()
            {
                ProjectId = 11,
                Code = "x_manager",
                CreationDate = DateTime.Now,
                DatabaseIp = "ip_manager",
                DatabaseName = "dbname_manager",
                DatabasePassword = "pwd_manager",
                DatabaseType = "type_manager",
                DatabaseUser = "user_manager",
                Description = "description_manager",
                ModifyDate = DateTime.Now,
                Name = "name_manager",
                Source = "source_manager"
            };
            // Added project
            projectManager.Add(project);
            uow.Commit();

            afterInsert = projectManager != null ? projectManager.GetCount() : -1;
            Assert.AreEqual(beforeInsert + 1, afterInsert);
            */
            
            ExecuteManager(uow =>
            { 
                projectManager = new ProjectManager(uow);
                beforeInsert = projectManager.GetCount();

                // Create Object type Project
                Project project = new Project()
                {
                    ProjectId = 11,
                    Code = "x_manager",
                    CreationDate = DateTime.Now,
                    DatabaseIp = "ip_manager",
                    DatabaseName = "dbname_manager",
                    DatabasePassword = "pwd_manager",
                    DatabaseType = "type_manager",
                    DatabaseUser = "user_manager",
                    Description = "description_manager",
                    ModifyDate = DateTime.Now,
                    Name = "name_manager",
                    Source = "source_manager"
                };
                // Added project
                projectManager.Add(project);

            }, () =>
            {

                afterInsert = projectManager != null ? projectManager.GetCount() : -1;
            });

            Assert.AreEqual(beforeInsert + 1, afterInsert);
        }
    }
}
